/*
 * $Id: OrderToEmailTransformer.java 19250 2010-08-30 16:53:14Z dirk.olmes $
 * --------------------------------------------------------------------------------------
 * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 *
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.txt file.
 */

package com.capgemini.mulefocus.email;

import org.mule.RequestContext;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractTransformer;
import org.mule.transformer.types.DataTypeFactory;
import org.mule.transport.email.MailProperties;

/**
 * Composes an e-mail notification message to be sent based on the Book Order.
 */
public class FagordEmailTransformer extends AbstractTransformer
{
    public FagordEmailTransformer()
    {
        super();
        registerSourceType(DataTypeFactory.create(String.class));
        setReturnDataType(DataTypeFactory.STRING);
    }
    
    @Override
    protected Object doTransform(Object src, String outputEncoding) throws TransformerException
    {
        String fagord = (String) src;
        
        String body =  "Det nye fagordet er: " + fagord;
        String toEmail="henrik@egil.net";
        RequestContext.getEventContext().getMessage()
        	.setOutboundProperty(MailProperties.TO_ADDRESSES_PROPERTY, toEmail);
        logger.info("Sending e-mail notification to " + toEmail);
        return body;
    }
}
